
var _pageSize = 50;// Grid默认行数
var _url = "/baseplatform/com/wxtf/platform/servlet/SystemControlServlet.thtf";
var _jsonObj = { 
	"classname": "",
	"methodname": "",
	"logicdata": "[{}]",
	"extenddata": "[{}]"
};

/**
 * 对startWith()的扩展
 */
String.prototype.trim = function() { 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
String.prototype.ltrim = function() { 
	return this.replace(/(^\s*)/g, ""); 
} 
String.prototype.rtrim = function() { 
	return this.replace(/(\s*$)/g, ""); 
}

function getCookie(name){
	var cookieValue = "";  
	var search = name + "=";  
	if(document.cookie.length > 0){   
		offset = document.cookie.indexOf(search);  
		if (offset != -1){   
			offset += search.length;  
			end = document.cookie.indexOf(";", offset);  
		if (end == -1) end = document.cookie.length;  
			cookieValue = unescape(document.cookie.substring(offset, end))  
		}  
	}  
	return cookieValue; 
}


/**
 * 对startWith()的扩展
 */
String.prototype.startWith=function(str){
	if(str==null||str==""||this.length==0||str.length>this.length){
		return false;
	}
	return (this.substr(0,str.length) == str);
}
/**
 * 对endWith()的扩展
 */
String.prototype.endWith = function(str){
	if(str==null||str==""||this.length==0||str.length > this.length){
		return false;
	}
	return(this.substring(this.length-str.length) == str);
}
/**
 * 对replaceAll()的扩展
 */
String.prototype.replaceAll = function(s1,s2) { 
    return this.replace(new RegExp(s1,"gm"),s2); 
}

/**
 * 将输入框中的字母变为大写
 */
function toUpper(ele){
	ele.value = ele.value.toUpperCase();
}

/**
 * ajax
 */
function callserver(jsonObj, succFunc, errorFunc){
	$.ajax({
		type: "post",
		url: _url,
		data: jsonObj,
		dataType: 'json',
		async:false,
		success: succFunc,
		error: errorFunc
	});
}

function succFunc(data, textStatus){
	//data.resultrecord
	
}

function errorFunc(data, textStatus){
	//data.resultrecord
	
}


/**
 *	弹出警告窗口
 *	msg 提示内容
 *	fn  回调函数
 */
function warningTip(msg){
	var warnWin = $.ligerDialog.warn(msg,'【系统提示信息】',function(){
		$('.l-window-mask').css("z-index","9000");
	});
	
	var len = $('.l-dialog').length;
	if(len > 1){
		$('.l-window-mask').css("z-index","9200");
	}
}

//自动消失的提示框
function succMsgTip(msg){
	var tip = $.ligerDialog.tip({
		height:120,
		title: '【系统提示信息】',
		content: msg,
		isHidden:false
	});
	setTimeout(function(){ tip.close(); }, 2500);
}



/**
	打开一个目标div窗口
 	target div的id值
 	title  窗口打开的名称
 	width  200 没有px
 	height 同上
 */
function initWindowByDiv(target, title, width, height){
	return $.ligerDialog.open({
		width: width,
		height: height,
		title:title,
		target: $("#"+target)
	});
}

function initWindowByDiv1(target, title, width, height, func){
	return $.ligerDialog.open({
		width: width,
		height: height,
		title:title,
		modal:true,
		allowClose: false,
		target: $("#"+target),
		buttons: [{
			text: '关闭', onclick: func
		}]
	});
}

function initWindowByDiv2(target, title, width, height, func){
	return $.ligerDialog.open({
		width: width,
		height: height,
		title:title,
		modal:true,
		allowClose: true,
		target: $("#"+target),
		buttons: [{
			text: '关闭', onclick: func
		}]
	});
}
function initWindowByDiv(target, title, width, height, func, func2){
	return $.ligerDialog.open({
		width: width,
		height: height,
		title:title,
		modal:true,
		allowClose: true,
		target: $("#"+target),
		buttons: [{
			text: '确定', onclick: func
		}, {
			text: '取消', onclick: func2
		}]
	});
}
/*
 * 关闭弹出窗口
 */
function closeWin(item, dialog) {
	dialog.hide();
}

/**
	打开一个Prompt窗口
 	title  		打开的名称
 	initValue   输出框默认值
 	funcallback 回调函数
 */
function alertPrompt(title,initValue,funcallback){
	$.ligerDialog.prompt(title,initValue,funcallback);
}


/*
 * 获取图标下拉框-grid配置项
 */
function getGridOptions(combo){
    return options = {
    	rownumbers:true, alternatingRow: true,usePager:false,
        switchPageSizeApplyComboBox: false,
        url: 'jsp/sys/menuIcons.jsp',
        checkbox: true,
        columns: [
	        { display: '图标', name: 'icon', align: 'center', width: 40,
	        	render:function(record, index, value, oth){
	        		return '<img src="ligerUI/skins/' + value + '" />';
	        	}
	         },
	        { display: '名称', name: 'key', minWidth: 100 }
        ],
        onClickRows: function(){
        	combo.selectBox.hide();
        },
        onCheckRow: function(checked, rowdata, rowindex) {
		    for (var rowid in this.records)
		        this.unselect(rowid); 
		    this.select(rowindex);
		},
        onBeforeCheckAllRow: function(checked, grid, element) { return false; }
    };
}


function sortArray(arr){
	var temp = '';
	for(var i=0; i<arr.length; i++){
		for (j = 0; j < arr.length; j++){
			if(arr[i] < arr[j]){
				temp = arr[j];
				arr[j] = arr[i];
				arr[i] = temp;
			}
		}
	}
}
/*
 * 获取当前时间 YYYY-MM-DD HH24:MM:SS
 */
function getCurDateTime(){
	var myDate = new Date();
	var y = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
	var m = myDate.getMonth();       //获取当前月份(0-11,0代表1月)
	var d = myDate.getDate();        //获取当前日(1-31)
	var h = myDate.getHours();       //获取当前小时数(0-23)
	var mi = myDate.getMinutes();     //获取当前分钟数(0-59)
	var s = myDate.getSeconds();     //获取当前秒数(0-59)
	
	m += 1;
	m = parseInt(m) < 10 ? '0'+m : m;
	d = parseInt(d) < 10 ? '0'+d : d;
	h = parseInt(h) < 10 ? '0'+h : h;
	mi = parseInt(mi) < 10 ? '0'+mi : mi;
	s = parseInt(s) < 10 ? '0'+s : s;
	
	return y +"-"+ m +"-"+ d +" "+ h +":"+ mi +":"+ s;
}
function getCurDate(){
	var myDate = new Date();
	var y = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
	var m = myDate.getMonth();       //获取当前月份(0-11,0代表1月)
	var d = myDate.getDate();        //获取当前日(1-31)
	
	m += 1;
	m = parseInt(m) < 10 ? '0'+m : m;
	d = parseInt(d) < 10 ? '0'+d : d;
	
	return y +"-"+ m +"-"+ d;
}

/**
 * 比较时间大小
 * d1,d2 YYYY-MM-DD
 * @return -1,0,1
 */
function compareDate(d1, d2){
	try{
		var t1 = d1.split("-");
		var t2 = d2.split("-");
		var d11 = new Date(t1[0],t1[1] - 1, t1[2]);
		var d22 = new Date(t2[0],t2[1] - 1, t2[2]);
		if(d11 < d22){
			return -1;
		} else if(d11 > d22){
			return 1;
		} else{
			return 0;
		}
	}catch(e){
		return null;
	}
}



/**
 * ajax下载文件
 * @param url 文件路径
 * @return
 */
function downloadFile(url){
	var elemIF = document.getElementById('downloadFrame');
	if(!elemIF){
		elemIF = parent.document.getElementById('downloadFrame');
	}
    elemIF.src = url;
    elemIF.style.display = "none";
}







/**
 * 查看对象的属性
 */
function allProps(obj) { 
    // 用来保存所有的属性名称和值
    var props = "";
    // 开始遍历
    for(var p in obj){ 
        // 方法
        if(typeof(obj[p])=="function"){ 
            //obj[p]();
        }else{ 
            // p 为属性名称，obj[p]为对应属性的值
            props += p + "=" + obj[p] + ";";
        } 
    } 
    // 最后显示所有的属性
    alert(props);
}

/**
 * 添加表单校验
 */
function validEvent(obj){
	var form
	if (typeof (obj) == "string")
        form = $("#"+obj);
    else if (typeof (obj) == "object" && obj.NodeType == 1)
        form = $(obj);
	form.validate({
        debug: true,
        errorPlacement: function (lable, element)
        {
            if (element.hasClass("textbg3"))
            {
                element.ligerTip({ content: lable.html(), target: element[0] }); 
            }
            else if (element.hasClass("textbg1"))
            {
                element.parent().ligerTip({ content: lable.html(), target: element[0] });
            }
            else if (element.is("select"))
            {
                element.parent().ligerTip({ content: lable.html(), target: element[0] });
            }
            else
            {
                 element.parent().ligerTip({ content: lable.html(), target: element[0] }); 
            }
        }
    });
    $.metadata.setType("attr", "validate");
}

/**
 * 加载表单
 */
function loadForm(mainform, data){
    if(data){
    	var o;
        for (var p in data){
        	o = $("#" +mainform+" #"+ p);
        	if(o.is("td")){
        		$("input[name='" + p + "'][value='" + data[p] + "']").attr("checked", true);
        	}else{
        		o.val(data[p]);
        	}
        }
    }
}

/**
 * 获取表单数据JSON
 */

function getForm(obj)
{
   	var form;var str;
   	if (typeof (obj) == "string")
        form = $("#"+obj);
	else if (typeof (obj) == "object" && obj.NodeType == 1)
        form = $(obj);
    try{
		str = JSON.stringify(form.serializeObject());
    	str = '['+str +']'; 
    	//str = str.replace('_txt_val',''); 
    }catch(a){
    	//alert(a);
    }
	return str;
};
/**
 * 清除气泡
 */

function clearAllTip()
{
   $("form input,textarea,select").ligerHideTip();
};
/**
 * 清除气泡
 */

function clearTip(id)
{
   $("#"+id).ligerHideTip();
};

$.fn.serializeObject = function() { 
	var o = {}; 
	var a = this.serializeArray(); 
	$.each(a, function() { 
		if (o[this.name]) { 
			o[this.name].push(this.value.trim() || ''); 
		} else { 
			o[this.name] = this.value.trim() || ''; 
		} 
	}); 
	return o; 
} 

//格式化日期格式
function formatdata(a){
	var reg =  /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
	var b = a;
	if(!reg.test(b)){
		b = b.replace(/\D/g,'');
		if(b.length >= 8){
			b = b.substring(0,4)+"-"+b.substring(4,6)+"-"+b.substring(6,8);
			if(!reg.test(b)){
				b = "";
			}
		}
	}
	return b;
}
